home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWLLLLooooccccaaaalllleeee((((3333CCCC++++++++)))) RRRRWWWWLLLLooooccccaaaalllleeee((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWLocale - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include <locale.h> #include <rw/locale.h> ((((AAAAbbbbssssttttrrrraaaacccctttt bbbbaaaasssseeee ccccllllaaaassssssss)))) DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn RRRRWWWWLLLLooooccccaaaalllleeee is an abstract base class. It defines an interface for formatting dates (including day and month names), times, numbers (including digit grouping), and currency, to and from strings. Note that because it is an aaaabbbbssssttttrrrraaaacccctttt base class, there is no way to actually enforce these goals -- the description here is merely the model of how a class derived from RRRRWWWWLLLLooooccccaaaalllleeee should act. There are three ways to use an RRRRWWWWLLLLooooccccaaaalllleeee object: By passing the object to functions which expect one, such as RRRRWWWWDDDDaaaatttteeee::::::::aaaassssSSSSttttrrrriiiinnnngggg(((()))).... By specifying a "global" locale using the static member function RRRRWWWWLLLLooooccccaaaalllleeee::::::::gggglllloooobbbbaaaallll((((RRRRWWWWLLLLooooccccaaaalllleeee****)))).... This locale is passed as the default argument to functions that use a locale. By "imbuing" a stream with the object, so that when an RRRRWWWWDDDDaaaatttteeee or RRRRWWWWTTTTiiiimmmmeeee is written to a stream using ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(((()))), the appropriate formatting will be used automatically. Two implementations of RRRRWWWWLLLLooooccccaaaalllleeee are provided with the library: Class RRRRWWWWLLLLooooccccaaaalllleeeeSSSSnnnnaaaappppsssshhhhooootttt encapsulates the Standard C library locale facility, with two additional advantages: more than one locale can be active at the same time; and it supports conversions ffffrrrroooommmm strings to other types. .in -5 There is also an internal class that mimics RRRRWWWWLLLLooooccccaaaalllleeeeSSSSnnnnaaaappppsssshhhhooootttt((((""""CCCC"""")))). If your compiler does not have built-in support for locales, one is constructed automatically at program startup to be used as the default value of RRRRWWWWLLLLooooccccaaaalllleeee::::::::gggglllloooobbbbaaaallll(((()))). If your compiler does support locales, RRRRWWWWLLLLooooccccaaaalllleeee::::::::gggglllloooobbbbaaaallll(((()))) returns a const reference to an instance of RRRRWWWWLLLLooooccccaaaalllleeeeSSSSnnnnaaaappppsssshhhhooootttt((((""""CCCC""""))))..in -5 PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee None EEEEnnnnuuuummmmeeeerrrraaaattttiiiioooonnnn enum CCCCuuuurrrrrrrrSSSSyyyymmmmbbbboooollll { NONE, LOCAL, INTL }; PPPPaaaaggggeeee 1111 RRRRWWWWLLLLooooccccaaaalllleeee((((3333CCCC++++++++)))) RRRRWWWWLLLLooooccccaaaalllleeee((((3333CCCC++++++++)))) Controls whether no currency symbol, the local currency symbol, or the international currency symbol should be used to format currency. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss virtual RWCString aaaassssSSSSttttrrrriiiinnnngggg(long) const = 0; virtual RWCString aaaassssSSSSttttrrrriiiinnnngggg(unsigned long) const = 0; Converts the number to a string (eeee....gggg...., """"3333,,,,444455556666""""). virtual RWCString aaaassssSSSSttttrrrriiiinnnngggg(double f, int precision = 6, RWBoolean showpoint = 0) const = 0; Converts the ddddoooouuuubbbblllleeee ffff to a string. The variable pppprrrreeeecccciiiissssiiiioooonnnn is the number of digits to place after the decimal separator. If sssshhhhoooowwwwppppooooiiiinnnntttt is TTTTRRRRUUUUEEEE, the decimal separator will appear regardless of the precision. virtual RWCString aaaassssSSSSttttrrrriiiinnnngggg(const struct tm* tmbuf,char format, const RWZone& zone) const = 0; Converts components of the ssssttttrrrruuuucccctttt ttttmmmm object to a string, according to the format character. The meanings assigned to the format character are identical to those used in the Standard C Library function ssssttttrrrrffffttttiiiimmmmeeee(((()))). The members of ssssttttrrrruuuucccctttt ttttmmmm are assumed to be set consistently. See for a summary of ssssttttrrrrffffttttiiiimmmmeeee(((()))) formatting characters. RWCString aaaassssSSSSttttrrrriiiinnnngggg(const struct tm* tmbuf,const char* format, const RWZone& zone) const; Converts components of the ssssttttrrrruuuucccctttt ttttmmmm object to a string, according to the format string. Each format character in the format string must be preceded by %%%%. Any characters not preceded by %%%% are treated as ordinary characters which are returned unchanged. You may represent the special character %%%% with "%%%%%%%%". The meanings assigned to the format character are identical to those used in the Standard C Library function ssssttttrrrrffffttttiiiimmmmeeee(((()))). The members of ssssttttrrrruuuucccctttt ttttmmmm are assumed to be set consistently. See for a summary of ssssttttrrrrffffttttiiiimmmmeeee(((()))) formatting characters. This function is not virtual in order to maintain link-compatibility with the previous version of the library. virtual RWCString mmmmoooonnnneeeeyyyyAAAAssssSSSSttttrrrriiiinnnngggg(double value,enum CurrSymbol = LOCAL) const = 0; PPPPaaaaggggeeee 2222 RRRRWWWWLLLLooooccccaaaalllleeee((((3333CCCC++++++++)))) RRRRWWWWLLLLooooccccaaaalllleeee((((3333CCCC++++++++)))) Returns a string containing the vvvvaaaalllluuuueeee argument formatted according to monetary conventions for the locale. The vvvvaaaalllluuuueeee argument is assumed to contain an integer representing the number of units of currency (eeee....gggg...., mmmmoooonnnneeeeyyyyAAAAssssSSSSttttrrrriiiinnnngggg((((1111000000000000....,,,, RRRRWWWWLLLLooooccccaaaalllleeee::::::::LLLLOOOOCCCCAAAALLLL)))) in a US locale would yield "$$$$11110000....00000000"). The CCCCuuuurrrrrrrrSSSSyyyymmmmbbbboooollll argument determines whether the local (eeee....gggg...., "$$$$") or international (eeee....gggg...., "UUUUSSSSDDDD ") currency symbol is applied, or none. virtual int mmmmoooonnnntttthhhhIIIInnnnddddeeeexxxx(const RWCString&) const = 0; Interprets its argument as a full or abbreviated month name, returning values 1 through 12 to represent (respectively) January through December, or 0 for an error. Leading white space is ignored. virtual RWBoolean ssssttttrrrriiiinnnnggggTTTTooooNNNNuuuummmm(const RWCString&, double* fp) const = 0; Interprets the RRRRWWWWCCCCSSSSttttrrrriiiinnnngggg argument as a floating point number. Spaces are allowed before and after the (optional) sign, and at the end. Digit group separators are allowed in the integer portion. Returns TTTTRRRRUUUUEEEE for a valid number, FFFFAAAALLLLSSSSEEEE for an error. If it returns FFFFAAAALLLLSSSSEEEE, the ddddoooouuuubbbblllleeee**** argument is untouched. All valid numeric strings are accepted; all others are rejected. The following are examples of valid numeric strings in an English-speaking locale: "1" " -02. " ".3" "1234.56" "1e10" "+ 19,876.2E+20" virtual RWBoolean ssssttttrrrriiiinnnnggggTTTTooooNNNNuuuummmm(const RWCString&, long* ip) const = 0; Interprets the RRRRWWWWCCCCSSSSttttrrrriiiinnnngggg argument as an integer. Spaces are allowed before and after the (optional) sign, and at the end. Digit group separators are allowed. Returns TTTTRRRRUUUUEEEE for a valid integer, FFFFAAAALLLLSSSSEEEE for an error. If it returns FFFFAAAALLLLSSSSEEEE, the lllloooonnnngggg**** argument is untouched. All valid numeric strings are accepted; all others are rejected. The following are examples of valid integral strings in an English-speaking locale: "1" " -02. " "+ 1,234" PPPPaaaaggggeeee 3333 RRRRWWWWLLLLooooccccaaaalllleeee((((3333CCCC++++++++)))) RRRRWWWWLLLLooooccccaaaalllleeee((((3333CCCC++++++++)))) "1234545" "1,234,567" Table 1. Formatting characters used by strftime(). EEEExxxxaaaammmmpppplllleeeessss aaaarrrreeee ggggiiiivvvveeeennnn ((((iiiinnnn ppppaaaarrrreeeennnntttthhhheeeessssiiiissss)))).... FFFFoooorrrr tttthhhhoooosssseeee ffffoooorrrrmmmmaaaattttssss tttthhhhaaaatttt ddddoooo nnnnooootttt uuuusssseeee aaaallllllll mmmmeeeemmmmbbbbeeeerrrrssss ooooffff tttthhhheeee ssssttttrrrruuuucccctttt ttttmmmm,,,, oooonnnnllllyyyy tttthhhhoooosssseeee mmmmeeeemmmmbbbbeeeerrrrssss tttthhhhaaaatttt aaaarrrreeee aaaaccccttttuuuuaaaallllllllyyyy uuuusssseeeedddd aaaarrrreeee nnnnooootttteeeedddd [[[[iiiinnnn bbbbrrrraaaacccckkkkeeeettttssss]]]].... FFFFoooorrrrmmmmaaaatttt cccchhhhaaaarrrraaaacccctttteeeerrrr MMMMeeeeaaaannnniiiinnnngggg EEEExxxxaaaammmmpppplllleeee aaaa Abbreviated weekday name [from ttttmmmm::::::::ttttmmmm____wwwwddddaaaayyyy] SSSSuuuunnnn AAAA Full weekday name [from ttttmmmm::::::::ttttmmmm____wwwwddddaaaayyyy] SSSSuuuunnnnddddaaaayyyy bbbb Abbreviated month name FFFFeeeebbbb BBBB Full month name FFFFeeeebbbbrrrruuuuaaaarrrryyyy cccc Date and time [may use all members] FFFFeeeebbbb 22229999 11114444::::33334444::::55556666 1111999988884444 dddd Day of the month 22229999 HHHH Hour of the 24-hour day 11114444 IIII Hour of the 12-hour day 00002222 jjjj Day of the year, from 001 [from ttttmmmm::::::::ttttmmmm____yyyyddddaaaayyyy] 66660000 mmmm Month of the year, from 01 00002222 MMMM Minutes after the hour 33334444 pppp AM/PM indicator, if any AAAAMMMM SSSS Seconds after the minute 55556666 UUUU Sunday week of the year, from 00 [from ttttmmmm::::::::ttttmmmm____yyyyddddaaaayyyy and ttttmmmm::::::::ttttmmmm____wwwwddddaaaayyyy] PPPPaaaaggggeeee 4444 RRRRWWWWLLLLooooccccaaaalllleeee((((3333CCCC++++++++)))) RRRRWWWWLLLLooooccccaaaalllleeee((((3333CCCC++++++++)))) wwww Day of the week, with 0 for Sunday 0000 WWWW Monday week of the year, from 00 [from ttttmmmm::::::::ttttmmmm____yyyyddddaaaayyyy and ttttmmmm::::::::ttttmmmm____wwwwddddaaaayyyy] xxxx Date [uses ttttmmmm::::::::ttttmmmm____yyyyddddaaaayyyy in some locales] FFFFeeeebbbb 22229999 1111999988884444 XXXX Time 11114444::::33334444::::55556666 yyyy Year of the century, from 00 (deprecated) 88884444 YYYY Year 1111999988884444 ZZZZ Time zone name [from ttttmmmm::::::::ttttmmmm____iiiissssddddsssstttt] PPPPSSSSTTTT or PPPPDDDDTTTT virtual RWBoolean ssssttttrrrriiiinnnnggggTTTTooooDDDDaaaatttteeee(const RWCString&, struct tm*) const = 0; Interprets the RRRRWWWWCCCCSSSSttttrrrriiiinnnngggg as a date, and extracts the month, day, and year components to the ttttmmmm argument. It returns TTTTRRRRUUUUEEEE for a valid date, FFFFAAAALLLLSSSSEEEE otherwise. If it returns FFFFAAAALLLLSSSSEEEE, the ssssttttrrrruuuucccctttt ttttmmmm argument is untouched; otherwise it sets the ttttmmmm____mmmmddddaaaayyyy, ttttmmmm____mmmmoooonnnn, and ttttmmmm____yyyyeeeeaaaarrrr members. If the date is entered as three numbers, the order expected is the same as that produced by ssssttttrrrrffffttttiiiimmmmeeee(((()))). Note that this function cannot reject all invalid date strings. The following are examples of valid date strings in an English-speaking locale: "Jan 9, 62" "1/9/62" "January 9 1962" "09Jan62" "010962" virtual RWBoolean ssssttttrrrriiiinnnnggggTTTTooooTTTTiiiimmmmeeee(const RWCString&, struct tm*) const = 0; Interprets the RRRRWWWWCCCCSSSSttttrrrriiiinnnngggg argument as a time, with hour, minute, and optional second. If the hour is in the range [1..12], the local equivalent of "AM" or "PM" is allowed. Returns TTTTRRRRUUUUEEEE for a valid time string, FFFFAAAALLLLSSSSEEEE for an error. If it returns FFFFAAAALLLLSSSSEEEE, the tm argument is untouched; otherwise it sets the ttttmmmm____hhhhoooouuuurrrr, ttttmmmm____mmmmiiiinnnn, and ttttmmmm____sssseeeecccc members. PPPPaaaaggggeeee 5555 RRRRWWWWLLLLooooccccaaaalllleeee((((3333CCCC++++++++)))) RRRRWWWWLLLLooooccccaaaalllleeee((((3333CCCC++++++++)))) Note that this function cannot reject all invalid time strings. The following are examples of valid time strings in an English-speaking locale: "1:10 AM" "13:45:30" "12.30.45pm" "PM 3:15" "1430" virtual RWBoolean ssssttttrrrriiiinnnnggggTTTTooooMMMMoooonnnneeeeyyyy(const RWCString&, double*, RWLocale::CurrSymbol=LOCAL) const = 0; Interprets the RRRRWWWWCCCCSSSSttttrrrriiiinnnngggg argument as a monetary value. The currency symbol, if any, is ignored. Negative values may be specified by the negation symbol or by enclosing parentheses. Digit group separators are optional; if present they are checked. Returns TTTTRRRRUUUUEEEE for a valid monetary value, FFFFAAAALLLLSSSSEEEE for an error. If it returns FFFFAAAALLLLSSSSEEEE, the ddddoooouuuubbbblllleeee**** argument is untouched; otherwise it is set to the integral number of monetary units entered (e.g. cents, in a U.S. locale). const RWLocale* iiiimmmmbbbbuuuueeee(ios& stream) const; Installs self in the ssssttttrrrreeeeaaaammmm argument, for later use by the operators <<<<<<<< and >>>>>>>> (e.g. in RRRRWWWWDDDDaaaatttteeee or RRRRWWWWTTTTiiiimmmmeeee). The pointer may be retrieved from the stream with the static member RRRRWWWWLLLLooooccccaaaalllleeee::::::::ooooffff(((()))). In this way a locale may be passed transparently through many levels of control to be available where needed, without intruding elsewhere. virtual int wwwweeeeeeeekkkkddddaaaayyyyIIIInnnnddddeeeexxxx(const RWCString&) const = 0; Interprets its argument as a full or abbreviated weekday name, returning values 1 through 7 to represent (respectively) Monday through Sunday, or 0 for an error. SSSSttttaaaattttiiiicccc PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss static const RWLocale& ooooffff(ios&); Returns the locale installed in the stream argument by a previous call to RRRRWWWWLLLLooooccccaaaalllleeee::::::::iiiimmmmbbbbuuuueeee(((()))) or, if no locale was installed, the result from RRRRWWWWLLLLooooccccaaaalllleeee::::::::gggglllloooobbbbaaaallll(((()))). PPPPaaaaggggeeee 6666 RRRRWWWWLLLLooooccccaaaalllleeee((((3333CCCC++++++++)))) RRRRWWWWLLLLooooccccaaaalllleeee((((3333CCCC++++++++)))) static const RWLocale* gggglllloooobbbbaaaallll(const RWLocale* loc); Sets the global "default" locale object to lllloooocccc, returning the old object. This object is used by RRRRWWWWDDDDaaaatttteeee and RRRRWWWWTTTTiiiimmmmeeee string conversion functions as a default locale. It is set initially to refer to an instance of a class that provides the functionality of RRRRWWWWLLLLooooccccaaaalllleeeeSSSSnnnnaaaappppsssshhhhooootttt((((""""CCCC"""")))). static const RWLocale& gggglllloooobbbbaaaallll(); Returns a reference to the present global "default" locale. const RWLocale* ddddeeeeffffaaaauuuullllttttLLLLooooccccaaaalllleeee(); Returns a pointer to a new instance of either RRRRWWWWLLLLooooccccaaaalllleeeeSSSSnnnnaaaappppsssshhhhooootttt((((""""CCCC"""")))); or another class that provides the same behavior for compilers that don't fully support Standard C locales. PPPPaaaaggggeeee 7777